package com.ymatou.iapi.m.couponservice.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.m.couponservice.parameter.GetApplyProductsBean;
import com.ymatou.iapi.m.couponservice.service.GetApplyProductsCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.model.YmtCouponProduct;
import com.ymttest.database.sqlwapper.YmtCouponProductWapper;
/**
*获取优惠券适用商品
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetApplyProducts{
	private static GetApplyProductsBean getapplyproductsBean;
	private static GetApplyProductsCall getapplyproductsCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取优惠券适用商品");
	}

	@Before
	public void caseUp() {
		getapplyproductsBean=new GetApplyProductsBean();
		getapplyproductsCall=new GetApplyProductsCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getapplyproductsCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetApplyProducts_001() {
		Logger.start(true,"更获取优惠券适用商品");
		try {
			YmtCouponProduct product = new YmtCouponProductWapper().selectTop1().get(0);
			
			int batchId=product.getBatchId();
			getapplyproductsBean.setBatchId(batchId);
			
			getapplyproductsCall.setData(getapplyproductsBean);
			getapplyproductsCall.callService();			
			
			Logger.verifyEquals("操作成功！", getapplyproductsCall.getMessage(), "验证返回Message");
			Logger.verifyEquals("0", getapplyproductsCall.getCode(), "验证返回StatusCode");

			List<YmtCouponProduct> products = new YmtCouponProductWapper().selectBysBatchId(batchId);
			List<String> returnProducts = getapplyproductsCall.getProductCodes().getProductCodes();
			
			Logger.verifyEquals(returnProducts.size(), products.size(), "验证YmtCouponProduct表生成相应记录数");
			
			for(int i=0;i<products.size();i++)
			{
				Logger.verifyEquals(returnProducts.get(i), products.get(i).getProductCode(), "验证YmtCouponProduct表productCodes");

			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetApplyProducts_002() {
		Logger.start(true,"BatchId空");
		try {
			getapplyproductsCall.setData(getapplyproductsBean);
			getapplyproductsCall.callService();			
			
			Logger.verifyEquals("操作成功！", getapplyproductsCall.getMessage(), "验证返回Message");
			Logger.verifyEquals("0", getapplyproductsCall.getCode(), "验证返回StatusCode");
		
			List<String> returnProducts = getapplyproductsCall.getProductCodes().getProductCodes();
			
			Logger.verifyEquals(0, returnProducts.size(), "验证YmtCouponProduct表生成相应记录数");
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetApplyProducts_003() {
		Logger.start(true,"BatchId不存在");
		try {
			int batchId=1345566767;
			getapplyproductsBean.setBatchId(batchId);
			
			getapplyproductsCall.setData(getapplyproductsBean);
			getapplyproductsCall.callService();			
			
			Logger.verifyEquals("操作成功！", getapplyproductsCall.getMessage(), "验证返回Message");
			Logger.verifyEquals("0", getapplyproductsCall.getCode(), "验证返回StatusCode");

			List<String> returnProducts = getapplyproductsCall.getProductCodes().getProductCodes();
					
			Logger.verifyEquals(0, returnProducts.size(), "验证YmtCouponProduct表生成相应记录数");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}